package com.openbravo.pos.payment;

import com.openbravo.pos.forms.AppConfig;
import com.openbravo.pos.forms.AppLocal;
import com.openbravo.pos.util.AltEncrypter;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.GroupLayout.ParallelGroup;
import javax.swing.GroupLayout.SequentialGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.LayoutStyle;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.filechooser.FileFilter;

public class ConfigPaymentPanelLinkPoint extends JPanel
  implements PaymentConfiguration
{
  private static File m_fCurrentDirectory = null;
  private JButton jButton1;
  private JLabel jLabel1;
  private JLabel jLabel3;
  private JLabel jLabel4;
  private JPasswordField jtxtCertificatePass;
  private JTextField jtxtCertificatePath;
  private JTextField jtxtStoreName;

  public ConfigPaymentPanelLinkPoint()
  {
    initComponents();
  }

  public JPanel getComponent()
  {
    return this;
  }

  public void loadProperties(AppConfig paramAppConfig)
  {
    String str1 = paramAppConfig.getProperty("payment.commerceid");
    String str2 = paramAppConfig.getProperty("payment.certificatePassword");
    String str3 = paramAppConfig.getProperty("payment.certificatePath");
    if ((str1 != null) && (str3 != null) && (str2 != null) && (str2.startsWith("crypt:")))
    {
      this.jtxtStoreName.setText(paramAppConfig.getProperty("payment.commerceid"));
      AltEncrypter localAltEncrypter = new AltEncrypter("cypherkey");
      this.jtxtCertificatePass.setText(localAltEncrypter.decrypt(paramAppConfig.getProperty("payment.certificatePassword").substring(6)));
      this.jtxtCertificatePath.setText(paramAppConfig.getProperty("payment.certificatePath"));
    }
  }

  public void saveProperties(AppConfig paramAppConfig)
  {
    AltEncrypter localAltEncrypter = new AltEncrypter("cypherkey");
    paramAppConfig.setProperty("payment.commerceid", comboValue(this.jtxtStoreName.getText()));
    paramAppConfig.setProperty("payment.certificatePath", comboValue(this.jtxtCertificatePath.getText()));
    paramAppConfig.setProperty("payment.certificatePassword", "crypt:" + localAltEncrypter.encrypt(new String(this.jtxtCertificatePass.getPassword())));
  }

  private String comboValue(Object paramObject)
  {
    return paramObject == null ? "" : paramObject.toString();
  }

  private void initComponents()
  {
    this.jLabel1 = new JLabel();
    this.jLabel3 = new JLabel();
    this.jLabel4 = new JLabel();
    this.jtxtStoreName = new JTextField();
    this.jtxtCertificatePass = new JPasswordField();
    this.jtxtCertificatePath = new JTextField();
    this.jButton1 = new JButton();
    this.jLabel1.setText(AppLocal.getIntString("label.storename"));
    this.jLabel3.setText(AppLocal.getIntString("label.certificatepwd"));
    this.jLabel4.setText(AppLocal.getIntString("label.certificatepath"));
    this.jButton1.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/fileopen.png")));
    this.jButton1.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        ConfigPaymentPanelLinkPoint.this.jButton1ActionPerformed(paramActionEvent);
      }
    });
    GroupLayout localGroupLayout = new GroupLayout(this);
    setLayout(localGroupLayout);
    localGroupLayout.setHorizontalGroup(localGroupLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(localGroupLayout.createSequentialGroup().addContainerGap().addGroup(localGroupLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(localGroupLayout.createSequentialGroup().addComponent(this.jLabel3).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(this.jtxtCertificatePass, -2, 180, -2)).addGroup(localGroupLayout.createSequentialGroup().addComponent(this.jLabel4).addGap(77, 77, 77).addComponent(this.jtxtCertificatePath, -2, 350, -2).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(this.jButton1, -2, 30, -2)).addGroup(localGroupLayout.createSequentialGroup().addComponent(this.jLabel1).addGap(71, 71, 71).addComponent(this.jtxtStoreName, -2, 180, -2))).addContainerGap(103, 32767)));
    localGroupLayout.setVerticalGroup(localGroupLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(localGroupLayout.createSequentialGroup().addGroup(localGroupLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(this.jtxtStoreName, -2, -1, -2).addComponent(this.jLabel1)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(localGroupLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(this.jtxtCertificatePass, -2, -1, -2).addComponent(this.jLabel3)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(localGroupLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(this.jButton1, -2, 25, -2).addGroup(localGroupLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(this.jtxtCertificatePath, -2, -1, -2).addComponent(this.jLabel4))).addContainerGap(-1, 32767)));
  }

  private void jButton1ActionPerformed(ActionEvent paramActionEvent)
  {
    JFileChooser localJFileChooser = new JFileChooser(m_fCurrentDirectory);
    localJFileChooser.addChoosableFileFilter(new ExtensionsFilter("PKCS12 certificates", new String[] { "p12" }));
    if (localJFileChooser.showOpenDialog(this) == 0)
    {
      File localFile = localJFileChooser.getSelectedFile();
      this.jtxtCertificatePath.setText(localFile.getAbsolutePath());
      m_fCurrentDirectory = localJFileChooser.getCurrentDirectory();
    }
  }

  private static class ExtensionsFilter extends FileFilter
  {
    private String message;
    private String[] extensions;

    public ExtensionsFilter(String paramString, String[] paramArrayOfString)
    {
      this.message = paramString;
      this.extensions = paramArrayOfString;
    }

    public boolean accept(File paramFile)
    {
      if (paramFile.isDirectory())
        return true;
      String str1 = paramFile.getName();
      int i = str1.lastIndexOf('.');
      if (i >= 0)
      {
        String str2 = str1.substring(i + 1);
        for (String str3 : this.extensions)
          if (str3.equalsIgnoreCase(str2))
            return true;
      }
      return false;
    }

    public String getDescription()
    {
      return this.message;
    }
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.pos.payment.ConfigPaymentPanelLinkPoint
 * JD-Core Version:    0.6.0
 */